package com.demo.resourcecode.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

	@Bean //返回一个bean并加入到Servlet/Spring上下文容器中
	public FilterRegistrationBean filterRegistrationBean() {
		FilterRegistrationBean reg = new FilterRegistrationBean();
		reg.setFilter(new MyFilter()); // 添加过滤器
		reg.setName("myLoginFilter"); // 设置过滤器名称
		reg.setOrder(1); // 设置过滤器顺序,数字大于0时越小,优先级越高
		return reg; // 返回并注入Spring容器中
	}

}